//
//  MyBalanceTableViewController.m
//  cityStar
//
//  Created by joyban on 14-12-27.
//  Copyright (c) 2014年 tiny. All rights reserved.
//

#import "MyBalanceTableViewController.h"
#import "BalancesView.h"
#import "UIActionSheet+Blocks.h"
#import "RIButtonItem.h"
#import "PersonalDetail.h"
#import "Define.h"
#import "KInterFace.h"
#import "HTDefine.h"
#import "RechargeViewController.h"

@interface MyBalanceTableViewController ()<CSBalanceDelegate,UIActionSheetDelegate>

@property(nonatomic,strong)BalancesView *balnce;
@property (weak, nonatomic) IBOutlet UIButton *chongzhiBtn;
@property (weak, nonatomic) IBOutlet UIButton *buyBtn;

@end

@implementation MyBalanceTableViewController

@synthesize balnce;

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"我的账户余额";
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
    
    [self addBackButton];
    self.chongzhiBtn.layer.cornerRadius = 4;
    self.buyBtn.layer.cornerRadius = 4;
    balnce = [[BalancesView alloc]initWithFrame:CGRectMake(14, 70, 293, 398)];
    balnce.delegate = self;
    [self.view addSubview:balnce];
    balnce.alpha = 0;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UIKeyBoard Notification Methods
- (void)keyboardWillShow:(NSNotification *)notification
{
    [self changeViewFrameWithKeyBoardNotification:notification isShow:YES];
}
- (void)keyboardWillHide:(NSNotification *)notification
{
    [self changeViewFrameWithKeyBoardNotification:notification isShow:NO];
}

- (void)changeViewFrameWithKeyBoardNotification:(NSNotification *)notification isShow:(BOOL)isShow
{
    NSDictionary *userInfo = [notification userInfo];
    //NSValue *keyFrameValue = userInfo[UIKeyboardFrameEndUserInfoKey];
    //CGRect keyboardFrame = [keyFrameValue CGRectValue];
    
    NSNumber *animationDur = userInfo[UIKeyboardAnimationDurationUserInfoKey];
    NSNumber *animationCur = userInfo[UIKeyboardAnimationCurveUserInfoKey];
    
    [UIView beginAnimations:@"changeViewFrame" context:nil];
    [UIView setAnimationCurve:[animationCur integerValue]];
    [UIView setAnimationDuration:[animationDur doubleValue]];
    [self.view setFrame:CGRectMake(0, isShow?-80:64, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame))];
    [UIView commitAnimations];
}

#pragma marKk _btn delegate

-(void)senderReturnClick:(UIButton *)btn
{
    [UIView animateWithDuration:0.6f animations:^{
        balnce.alpha = 0;
    }];
}

-(void)senderCancleoactClick:(UIButton *)btn
{
    [UIView animateWithDuration:0.6f animations:^{
        balnce.alpha = 0;
    }];
}

- (IBAction)Recharge_Action:(id)sender {

    NSData *userData = [KStandUserDefaults objectForKey:KUserDefaultKey_PersonalDetail];
    PersonalDetail *user = [NSKeyedUnarchiver unarchiveObjectWithData:userData];
    
    RIButtonItem *cancelItem = [RIButtonItem itemWithLabel:@"取消"];
    RIButtonItem *yinlianItem = [RIButtonItem itemWithLabel:@"银联支付" action:^{
        NSString *chargeUrl = [NSString stringWithFormat:@"http://api.icszx.com/recharge/charge/money/1/trackid/%@",user.trackid];
        RechargeViewController *rechargeVC = [[RechargeViewController alloc]initWithRechangeUrl:chargeUrl];
        [self.navigationController pushViewController:rechargeVC animated:YES];
    }];
    RIButtonItem *apayItem = [RIButtonItem itemWithLabel:@"支付宝支付" action:^{
        NSString *chargeUrl = [NSString stringWithFormat:@"http://api.icszx.com/recharge/charge/money/1/trackid/%@",user.trackid];
        RechargeViewController *rechargeVC = [[RechargeViewController alloc]initWithRechangeUrl:chargeUrl];
        [self.navigationController pushViewController:rechargeVC animated:YES];
    }];
    
    UIActionSheet *sheet = [[UIActionSheet alloc]initWithTitle:@"立即充值" cancelButtonItem:cancelItem destructiveButtonItem:yinlianItem otherButtonItems:apayItem, nil];
    [sheet showInView:self.view];
    
}

- (IBAction)Mentionnow_Action:(id)sender {
    balnce.nameLabel.text = @"申请提现";
    balnce.textOne.placeholder = @"请输入提现金额";
    [UIView animateWithDuration:0.6f animations:^{
        balnce.alpha = 1;
    }];
}

/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
    
    // Configure the cell...
    
    return cell;
}
*/

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
